package com.wtx.chapter06;

/**
 * @description: 从右到左求二进制幂
 * @author: wtx
 * @createDate: 2020/6/10
 */
public class RightToleft {

    public static int solution(int a, int[] array){

        int res = 0;
        int temp = a;
        if (array[array.length-1]==1)
            res = a;
        else
            res = 1;
        for (int i = array.length-2; i >= 0; i--){
            temp = temp*temp;
            if (array[i]==1)
                res = res*temp;
        }
        return res;
    }


    public static void main(String[] args) {

        int[] arr = {1,0,0};
        System.out.println(RightToleft.solution(2,arr));
    }
}
